﻿
@model Fap.AspNetCore.ViewModel.MultiJqGridViewModel
@{
    Layout = null;
    //指派角色
    Fap.AspNetCore.ViewModel.JqGridViewModel bizRole = Model.JqGridViewModels["FapBizRole"];
    //动态角色
    Fap.AspNetCore.ViewModel.JqGridViewModel dynRole = Model.JqGridViewModels["FapBizDynRole"];
}
<title>业务角色</title>

<div class="row">
    <div class="col-xs-12">
        <div class="tabbable">
            <ul class="nav nav-tabs" id="myTab">
                <li class="active">
                    <a data-toggle="tab" href="#bizRole">
                        <i class=" blue ace-icon fa  fa-users bigger-120"></i>
                        指派角色
                    </a>
                </li>

                <li>
                    <a data-toggle="tab" href="#dynRole">
                        <i class="green ace-icon fa fa-user bigger-120"></i>
                        动态角色
                    </a>
                </li>


            </ul>

            <div class="tab-content">
                <div id="bizRole" class="tab-pane fade in active">
                    <div class="row">
                        <div class="col-xs-12 col-sm-3">
                            <div class="widget-box">
                                <div class="widget-header widget-header-flat">
                                    <h4 class="widget-title">角色</h4>

                                    <fap-tree-button id="bizrole" description="指定角色" tree-id="tree-bizrole"></fap-tree-button>
                                </div>

                                <div class="widget-body">
                                    <div class="widget-main">
                                        <fap-tree id="bizrole" is-async="true" get-url="/System/Api/Manage/BusinessRole" edit-url="/System/Api/Manage/BusinessRole"></fap-tree>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="col-xs-12 col-sm-9">
                            <div class="widget-box">
                                <div class="widget-header widget-header-flat">
                                    <h4 class="widget-title">员工</h4>

                                    <div class="widget-toolbar">
                                        <a href="#" data-action="fullscreen" class="orange2">
                                            <i class="ace-icon fa fa-expand"></i>
                                        </a>
                                    </div>                                  
                                </div>
                                <div class="widget-body">
                                    <div class="widget-main">
                                        <fap-grid id="bizRole" grid-model="bizRole" on-form-init-add="afterInitFormCallback"
                                                  multi-select="true" multi-box-only="true" shrink-fit="false" view-records="true" wrapper="widget-main"></fap-grid>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

                <div id="dynRole" class="tab-pane fade">
                  
                    <fap-grid id="dynRole" grid-model="dynRole" wrapper="myTab,dynRole"
                              oper-delete="true" view-records="true"></fap-grid>
                    <div class="space-6"></div>
                    <div class="alert alert-warning">
                        （1）SQL结果必须返回人员Fid值；
                        （2）自动绑定只支持占位符：{申请人}表示申请人； 
                        （3）手动绑定可支持占位符：{申请人}表示申请人； {指定字段}表示从表单中指定关联字段
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>


<script>
    var afterInitFormCallback = function () {
        var tree = $('#tree-bizrole').jstree(true);
        var sel = tree.get_selected();
        if (sel.length) {
            $("#BizRoleUid").val(sel[0]).next().val(tree.get_node(sel[0]).text);
        }
    }
    var scripts = [null, null]
    $('.page-content-area').ace_ajax('loadScripts', scripts, function () {
        jQuery(function ($) {
            $(document).one('ajaxloadstart.page', function (e) {
                $('#tree-bizrole').jstree("destroy");
            })          
            $('#tree-bizrole').on("changed.jstree", function (e, data) {
                if (data && data.selected && data.selected.length) {
                    var roleId = data.selected[0];
                    //显示所有角色组的角色
                    var filter = { "groupOp": "AND" };
                    if (roleId == "0") {
                        reloadGrid("grid-bizRole");
                    } else {
                        filter.rules = [{ "field": "BizRoleUid", "op": "eq", "data": roleId }];
                        reloadGrid("grid-bizRole",{ 'filters': JSON.stringify(filter) });
                    }
                }
            }); 
        })
    })

</script>
